package com.ruoyi.wechat.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.wechat.mapper.OrderDetailMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.wechat.mapper.OrderMapper;
import com.ruoyi.wechat.domain.Order;
import com.ruoyi.wechat.service.IOrderService;

/**
 * orderService业务层处理
 * 
 * @author yeluochen
 * @date 2024-12-29
 */
@Service
public class OrderServiceImpl implements IOrderService 
{
    @Autowired
    private OrderDetailMapper orderDetailMapper;
    @Autowired
    private OrderMapper orderMapper;

    /**
     * 查询order
     * 
     * @param orderId order主键
     * @return order
     */
    @Override
    public Order selectOrderByOrderId(String orderId)
    {
        return orderMapper.selectOrderByOrderId(orderId);
    }

    /**
     * 查询order列表
     * 
     * @param order order
     * @return order
     */
    @Override
    public List<Order> selectOrderList(Order order)
    {
        return orderMapper.selectOrderList(order);
    }

    @Override
    public List<Order> selectOrderAndDetailList(Order order)
    {
        return orderMapper.selectOrderAndDetailList(order);
    }

    /**
     * 新增order
     * 
     * @param order order
     * @return 结果
     */
    @Override
    public int insertOrder(Order order)
    {
        order.setOrderId(IdUtils.randomUUID());
        order.setOrderTime(DateUtils.getNowDate());
        order.setQrCode("hkjdfhkjafdjhkfjhka");
        order.setOrderStatus(0l);
        for (int i = 0; i < order.getOrderDetails().size(); i++)    {
            order.getOrderDetails().get(i).setOrderDetailId(IdUtils.randomUUID());
            order.getOrderDetails().get(i).setOrderId(order.getOrderId());
            orderDetailMapper.insertOrderDetail(order.getOrderDetails().get(i));
        }
        return orderMapper.insertOrder(order);
    }

    /**
     * 修改order
     * 
     * @param order order
     * @return 结果
     */
    @Override
    public int updateOrder(Order order)
    {
        return orderMapper.updateOrder(order);
    }

    /**
     * 批量删除order
     * 
     * @param orderIds 需要删除的order主键
     * @return 结果
     */
    @Override
    public int deleteOrderByOrderIds(String[] orderIds)
    {
        return orderMapper.deleteOrderByOrderIds(orderIds);
    }

    /**
     * 删除order信息
     * 
     * @param orderId order主键
     * @return 结果
     */
    @Override
    public int deleteOrderByOrderId(String orderId)
    {
        return orderMapper.deleteOrderByOrderId(orderId);
    }
}
